<?php

namespace App\Admin\Controllers;


use App\Models\Supplier;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class SupplierController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '供应商管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Supplier());
        $grid->disableExport();
        $grid->column('id', __('ID'))->sortable();
        $grid->column('name', __('供应商名称'));
        $grid->column('number', __('供应商编号'));
        $grid->column('mobile', __('联系方式'));
        $grid->column('address', __('地址'));
        $grid->column('created_at', __('创建时间'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed   $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Supplier::findOrFail($id));

        $show->field('id', __('ID'));
        $show->field('name', __('供应商名称'));
        $show->field('number', __('供应商编号'));
        $show->field('mobile', __('联系方式'));
        $show->field('address', __('地址'));


        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Supplier());
        $form->text('name', __('供应商名称'));
        $form->text('number', __('供应商编号'));
        $form->text('mobile', __('联系方式'));
        $form->text('address', __('地址'));
        $form->footer(function ($footer) {

            // 去掉`查看`checkbox
            $footer->disableViewCheck();

            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();

            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });
        return $form;
    }
}
